/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */


/**
 * Note: The returned array must be malloced, assume caller calls free().
 */


int GetSize(struct TreeNode* root){
    if(!root)
        return 0;
    return 1 + GetSize(root->left) + GetSize(root->right);
}

void PosOrder(struct TreeNode* root, int* arr, int* returnSize){
    if(!root){
        return;
    }
    PosOrder(root->left,arr,returnSize);
    PosOrder(root->right,arr,returnSize);
    arr[(*returnSize)++] = root->val;
    return;
}
int* postorderTraversal(struct TreeNode* root, int* returnSize){
    if(!root){
        *returnSize = 0;
        return NULL;
    }
    *returnSize = 0;
    int size = GetSize(root);
    int* arr = (int*)malloc(sizeof(int) * size);
    PosOrder(root, arr, returnSize);
    return arr;
}